package com.sise.controller;

import com.sise.bean.CodeMsg;
import com.sise.entity.ProductType;
import com.sise.entity.StoreInfo;
import com.sise.service.IStoreInfoService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zj
 */
@RestController
@RequestMapping("/sise/store-info")
public class StoreInfoController {

    @Resource
    private IStoreInfoService storeInfoService;

    @PostMapping("/updateById")
    public CodeMsg updateById(StoreInfo storeInfo) {
        boolean isUpdate = storeInfoService.updateById(storeInfo);
        if (isUpdate) {
            return new CodeMsg().setCode(200).setMsg("修改成功！");
        }
        return new CodeMsg().setCode(400).setMsg("修改失败！");
    }

    @RequestMapping("/findById")
    public StoreInfo findById(Integer id) {
        return storeInfoService.findById(id);
    }

    @RequestMapping("/findAll")
    public ModelAndView findAll() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/index-BusinessInformation");
        modelAndView.addObject("shops", storeInfoService.findAll());
        return modelAndView;
    }

    @RequestMapping("/getAllShopInfo")
    public List<StoreInfo> getAllShopInfo() {
        return storeInfoService.findAll();
    }

    @RequestMapping("/getShopInfo")
    public CodeMsg<List<StoreInfo>> getShopInfo() {
        return storeInfoService.getShopInfo();
    }

    @RequestMapping("addStoreInfo")
    public CodeMsg<String> addStoreInfo(StoreInfo storeInfo, ProductType productType) {
        return storeInfoService.addStoreInfo(storeInfo, productType);
    }

    @RequestMapping("updateStoreInfo")
    public CodeMsg<String> updateStoreInfo(StoreInfo storeInfo) {
        return storeInfoService.updateStoreInfo(storeInfo);
    }

    @RequestMapping("updateStoreInfoByRest")
    public CodeMsg<String> updateStoreInfoByRest(int[] storeIds) {
        return storeInfoService.updateStoreInfoByRest(storeIds);
    }

    @RequestMapping("updateStoreInfoByBusiness")
    public CodeMsg<String> updateStoreInfoByBusiness(int[] storeIds) {
        return storeInfoService.updateStoreInfoByBusiness(storeIds);
    }
}
